#ifndef CHARTVIEWEX_H
#define CHARTVIEWEX_H

#include <QtCharts/QChartView>
#include <QtCharts/QSplineSeries>
#include <QtCharts/QAbstractSeries>
#include <QtCharts/QChart>
#include <QValueAxis>
#include <QWidget>
#include <QMenu>
#include <QList>
#include <QPixmap>
#include <QDialog>
#include <QLabel>
#include <QPushButton>
#include <QSpinBox>
#include <QComboBox>
#include <QLineEdit>
#include <QGroupBox>
#include <QVBoxLayout>
#include <QRubberBand>
#include "callout.h"
#include "ccurvedata.h"
QT_CHARTS_USE_NAMESPACE

class ChartViewEx : public QChartView
{
    Q_OBJECT
public:
    ChartViewEx(QWidget *parent=0);
    void AddCurveData(CCurveData *data);
    void setXAxisName(const QString &name);
    void setYAxisName(const QString &name);
    void setChartName(const QString &name);
    void saveImage();
    void ClearAll();
private:
    void createActions();
    void createDialog();
    void fillColorList(QComboBox *cbBox);
    void checkPointValid(QPointF &pos);

protected:
    void contextMenuEvent(QContextMenuEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void wheelEvent(QWheelEvent *e);
private slots:
    void setHoveredSigal(const QPointF &point, bool state);
    void showSetPropertyDialog();
    void legendVisible();
    void markerVisible();
    void handleMarkerClicked();
    void SelectAllNorNot();
    void hoveredEnable();
    void getLegendAlign(int index);
    void getLineType(int index);
    void getLineName(const QString &name);
    void getLineWidth(int index);
    void getColor(int index);

private:
    QMenu *popMenu;
    QAction *setCurvePropertyAction;
    QAction *saveImgAction;
    QAction *legendVisibleAction;
    QAction *markerAction;
    QAction *hoveredEnableAction;
    QAction *selectAllCurve;
    QAction *hideAllCurve;
    QChart* mChart;
    QPointF posStart;
    QPointF posEnd;
    QPointF posCur;

    bool isZoomIn;
    bool isZoomOut;
    bool isPress;
    bool isHoverd;
    bool isLegendVisible;
//    bool isDisplayAll;
//    bool isHideAll;
    bool isMarkerVisible;
    bool isHoveredEnable;
    qreal mXMin;
    qreal mXMax;
    qreal mYMin;
    qreal mYMax;
    qreal mZoomFactor;

    QDialog *curveDialog;
    QLabel *lbLineName;
    QLabel *lbLineType;
    QLabel *lbLineWidth;
    QLabel *lbColor;
    QSpinBox *spinBoxLineWidth;
    //QPushButton *btnColor;
    QComboBox *cbBoxLineColor;
    QLineEdit *lELineName;
    QComboBox *cbBoxLineType;


    QDialog *chartDialog;
    QLabel *lbChartBackground;
    QLabel *lbLegendAlign;
    QLabel *lbChartTitle;
    QLabel *lbXAixsName;
    QLabel *lbYAxisName;
    QLabel *lbZoomFactor;
    //QPushButton *btnBackgroundColor;
    QComboBox *cbBoxBkColor;
    QComboBox *cbBoxLegendAlign;
    QLineEdit *lEChartTitle;
    QLineEdit *lEXAxisName;
    QLineEdit *lEYAxisName;
    QDoubleSpinBox *spinBoxZoomFactor;
    QValueAxis *xAxis;
    QValueAxis *yAxis;
    QLineSeries* currentSeries ;
    QLineSeries* currentHorverSeries ;
    CallOut *m_tooltip;
    QRubberBand *m_rubberBand;
};

#endif // CHARTVIEWEX_H
